package com.cetc.testkafka.kafkaconsumer;

import com.cetc.testkafka.common.TopicConst;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * kafka消费者测试
 */
@Component
public class SimpleKafkaConsumer {

    @KafkaListener(topics = {"${kafka.topic1}"}, groupId = "${kafka.consumer.group.id}",containerFactory = "kafkaListenerContainerFactory")
    //@KafkaListener(topics = {"${kafka.topic1}"},containerFactory = "kafkaListenerContainerFactory")
    //@KafkaListener(topics = {"${kafka.topic1}"}, groupId = "${kafka.consumer.group.id}")
    public void receiveMessage(ConsumerRecord<?,?> consumerRecord) {
        System.out.println("1: "+consumerRecord.toString());
    }

    @KafkaListener(topics = {"${kafka.topic1}"}, groupId = "${kafka.consumer2.group.id}",containerFactory = "kafkaListenerContainerFactory2")
    public void receiveMessage2(ConsumerRecord<?,?> consumerRecord) {
        System.out.println("2: " +consumerRecord.toString());
    }
}
